home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15999 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  6.8 KB

  1. Path: news.iadfw.net!usenet
  2. From: jveigel@airmail.net (Jens Veigel)
  3. Newsgroups: comp.lang.c++
  4. Subject: Is there an easier way to do this in C ?
  5. Date: Mon, 08 Apr 1996 04:35:27 GMT
  6. Organization: Guest user
  7. Message-ID: <4kcpio$a0o@airnews.iadfw.net>
  8. NNTP-Posting-Host: dal36-27.ppp.iadfw.net
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. I'm porting an ASPECT (Procomm f win) script to C in Windows and I'm
  12. at the portion where I need to build several list.txt files for my
  13. comboboxes to display filenames longer than 8 characters. The way I do
  14. it in my script is to "cruise" the directories stuff them into an
  15. array and then build the files. My question is: 
  16.  
  17. Is there an easier way to do this than the script below ?
  18. If not I will have to port it to C and add the missing features like
  19. stringinsert and stringextract myself and do it the way I'm doing it
  20. now.  I'm just wondering if I could somehow use some sort of lookup
  21. table where I would store my created dir structure each time a sub dir
  22. is created or deleted, instead of having to run this everytime a new
  23. subdir under the "\top & \bot"  has been created, so I'm current as
  24. far as my file combobox text files are concerned. I reverse the
  25. process when a filename of lets say 69557904031 has been picked from
  26. the combobox, I then insert slashes and build a path like so
  27. d:\mpm\line1\top\695\57904031\*.* from which I transmit files. 
  28. Not only takes an array this size a lot of memory but also some time
  29. to "cruise through the dirs to which I add daily 4 or five.
  30. BTW: what's the equivalent to $nullstr in C ? 
  31.  
  32. Any suggestions would be greatly appreciated. 
  33.  
  34. here is how I do it today, again this is not C but aspect but looks
  35. almost like C, except strings are diff in C and of course the array
  36. would be differently acessed ....
  37.  
  38. string  FabArray[10][200][20]
  39. string  linedef, Linedef1t , Linedef1b, Linedef2t, Linedef2b,
  40. Linedef3t, Linedef3b
  41.  
  42. string Filelist
  43. string Listfile
  44.  
  45.  
  46. proc MAIN 
  47.  
  48. Linedef="d:\mpm"
  49. Linedef1t="d:\mpm\line1\top"
  50. Linedef1b="d:\mpm\line1\bot"
  51. Linedef2t="d:\mpm\line2\top"
  52. Linedef2b="d:\mpm\line2\bot"
  53. Linedef3t="d:\mpm\line3\top"
  54. Linedef3b="d:\mpm\line3\bot"
  55.  
  56.  
  57.  
  58. Listfile="Line.txt"
  59.   strcpy Linedef Linedef1t           ;line1\top
  60.   filelist=Linedef
  61. GetList(Linedef)
  62.  
  63. pause 2
  64.   strcpy Linedef Linedef2t             ;line2\top 
  65.   filelist=Linedef
  66. GetList(Linedef)
  67.  
  68. pause 2
  69.   strcpy Linedef Linedef3t              ;line3\top
  70.   filelist=Linedef
  71. GetList(Linedef)
  72.  
  73.  
  74.  
  75. pause 2
  76.   strcpy Linedef Linedef1b            ;line1\bottom
  77.   filelist=Linedef 
  78. GetList(Linedef)
  79.  
  80.  
  81. pause 2
  82.   strcpy Linedef Linedef2b              ;line2\bottom
  83.   filelist=Linedef
  84. GetList(Linedef)
  85.  
  86.  
  87.  
  88. pause 2
  89.   strcpy Linedef LineDef3b            ;line3\bottom
  90.   filelist=Linedef    
  91. GetList(Linedef)
  92.  
  93. endproc
  94.  
  95.  
  96. proc Getlist
  97. param string Leader
  98. integer one, two, three
  99. string line, strvar1, strvar2, strvar3, Level1, Level2, Level3
  100.  
  101. ;clear any old array contents
  102. for one=0 upto 9
  103.         for two=0 upto 199
  104.     for three=0 upto 19
  105.            FabArray[one][two][three]=$nullstr
  106.     endfor
  107.         endfor
  108. endfor            
  109.  
  110. ; get subdirectories in the first level
  111.    one=0
  112.    strvar1=Leader
  113.    addfilename strvar1 "*.*"
  114.    if findfirst strvar1 "D"                        ; findfirst Level1
  115.       Level1=$filename
  116.       strfind Level1 "."
  117.       if failure
  118.          FabArray[one][0][0]=Level1
  119.         strcat Level1 " "
  120.         strupr level1
  121.         usermsg level1
  122.          one++
  123.       endif
  124.       while findnext                               ; findnext Level1
  125.          Level1=$filename        
  126.          if strfind Level1 "."
  127.             loopwhile
  128.          else
  129.             FabArray[one][0][0]=Level1
  130.             one++
  131.          endif
  132.       endwhile
  133.    endif
  134. ; get subdirectories in the second level
  135.    for one=0 upto 29
  136.       two=1
  137.       strvar2=FabArray[one][0][0]
  138.       if strcmp strvar2 $nullstr
  139.          exitfor
  140.       else
  141.          strinsert strvar2 "\" 0
  142.          strinsert strvar2 Leader 0
  143.          addfilename strvar2 "*.*"
  144.       endif
  145.       if findfirst strvar2 "D"                        ; findfirst
  146. Level2
  147.          Level2=$filename
  148.          strfind Level2 "."
  149.          if failure
  150.             strcmp Level2 $nullstr
  151.             if failure
  152.                FabArray[one][two][0]=Level2
  153.                two++
  154.             endif
  155.          endif
  156.          while findnext                               ; findnext
  157. Level2
  158.             Level2=$filename        
  159.             if strfind Level2 "."
  160.                loopwhile
  161.             else
  162.                strcmp Level2 $nullstr
  163.                if failure
  164.                   FabArray[one][two][0]=Level2
  165.                   two++
  166.                else
  167.                   exitwhile
  168.                endif
  169.             endif
  170.          endwhile
  171.       endif
  172.    endfor
  173. ; get subdirectories in the third level
  174.    for one=0 upto 9
  175.       for two=1 upto 199
  176.          three=1
  177.          Level1=FabArray[one][0][0]
  178.          Level2=FabArray[one][two][0]
  179.          strvar3=Level2
  180.          if strcmp strvar3 $nullstr
  181.             exitfor
  182.          else
  183.             strinsert strvar3 "\" 0
  184.             strinsert strvar3 Level1 0
  185.             strinsert strvar3 "\" 0
  186.             strinsert strvar3 Leader 0
  187.             addfilename strvar3 "*.*"
  188.          endif
  189.          if findfirst strvar3 "D"                        ; findfirst
  190. Level3
  191.             Level3=$filename
  192.             strfind Level3 "."
  193.             if failure
  194.                strcmp Level3 $nullstr
  195.                if failure
  196.                   FabArray[one][two][three]=Level3
  197.                   three++
  198.                endif
  199.             endif
  200.             while findnext                               ; findnext
  201. Level3
  202.                Level3=$filename        
  203.                if strfind Level3 "."
  204.                   loopwhile
  205.                else
  206.                   strcmp Level3 $nullstr
  207.                   if failure
  208.                      FabArray[one][two][three]=Level3
  209.                      three++
  210.                   else
  211.                      exitwhile
  212.                   endif
  213.                endif
  214.             endwhile
  215.          endif
  216.       endfor
  217.    endfor
  218. ; generate file for use in fcombobox
  219.    ;fetch aspect path FileList
  220.  
  221.    addfilename FileList listfile
  222.  
  223.    fopen 0 FileList create text
  224.  
  225.    for one=0 upto 9
  226.       Level1=FabArray[one][0][0]
  227.       if strcmp Level1 $nullstr
  228.          exitfor
  229.       endif
  230.       for two=1 upto 199
  231.          Level2=FabArray[one][two][0]
  232.          if strcmp Level2 $nullstr
  233.             if two==1
  234.                fputs 0 Level1
  235.             endif
  236.             exitfor
  237.          else
  238.             for three=1 upto 19
  239.                Level3=FabArray[one][two][three]
  240.                if strcmp Level3 $nullstr
  241.                   if three==1
  242.                      line=Level1
  243.                      strcat line Level2
  244.                      fputs 0 line
  245.                   endif
  246.                   exitfor
  247.                endif
  248.                line=Level1
  249.     strcat line Level2
  250.                strcat line Level3
  251.                fputs 0 line
  252.             endfor
  253.          endif
  254.       endfor
  255.    endfor
  256.    fclose 0
  257. endproc ;GetList
  258.  
  259.  
  260.  
  261.